<template>
  <div
    :style="{ width: width, height: height }"
    :id="props.id"
    :option="props.option"
  ></div>
</template>

<script setup>
import { ref, nextTick, onMounted } from "vue";
import * as echarts from "echarts";
const props = defineProps({
  id: {
    type: String,
    required: true,
  },
  option: {
    type: Object,
    required: false,
  },
  width: {
    type: String,
    required: false,
    default: () => "200px",
  },
  height: {
    type: String,
    required: false,
    default: () => "200px",
  },
});
onMounted(() => {
  GetEchar();
});

const GetEchar = () => {
  const myCharts = ref();
  nextTick(() => {
    myCharts.value = echarts.init(document.getElementById(props.id));
    myCharts.value.setOption(props.option);
    // 让图表跟随屏幕自动的去适应
    // if (myCharts.value) {
    //   window.addEventListener("resize", function () {
    //     myCharts.value.resize();
    //   });
    // }
  });
};
</script>

<style lang="scss" scoped>
.echart_size {
  width: 100%;
  height: 100%;
}
</style>
